package com.example.seven.mynews.fragment;

import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.example.seven.mynews.adapter.SimpleAdapter;

import com.example.seven.mynews.R;
import com.example.seven.mynews.data.News;
import com.example.seven.mynews.data.XMLPullToListData;
import com.example.seven.mynews.data.XMLRequest;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by seven on 16-6-30.
 */
public class Flagment1 extends Fragment {

    private RecyclerView recyclerView;
    private SwipeRefreshLayout swipeRefresh;
    private String url="http://news.qq.com/newsgn/rss_newsgn.xml";
    XMLPullToListData xmlp = new XMLPullToListData();


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final View view = inflater.inflate(R.layout.flagment_1,container,false);
        recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView1);
        swipeRefresh = (SwipeRefreshLayout) view.findViewById(R.id.swipeRefresh1);
        //设置颜色变化四色
        swipeRefresh.setColorSchemeColors(Color.parseColor("#ff00ff"),Color.parseColor("#ff0f0f"),Color.parseColor("#0000ff"),Color.parseColor("#000000"));
        //调用 抓取数据
        xmlp.XMLPullDataInstance(view,recyclerView,url);

        //刷新事件
        swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                xmlp.XMLPullDataInstance(view,recyclerView,url);
                //延迟3秒刷新结束后，进度条消失
                swipeRefresh.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        swipeRefresh.setRefreshing(false);
                    }
                },3000);
            }
        });

        return view;
    }



    /**
     * 传递参数
     * @param title
     * @return
     */
    public static Flagment1 newInstance(String title){
        Flagment1 f1 = new Flagment1();
        Bundle bundle = new Bundle();
        bundle.putString("title",title);
        f1.setArguments(bundle);
        return f1;
    }
}
